package com.ts.tsavplayer

import android.os.Bundle
import android.util.Log
import android.view.SurfaceHolder
import android.view.SurfaceView
import android.view.Window
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import com.ts.tsavplayer.player.AVPlayer
import com.ts.tsavplayer.player.AVPlayer.Companion.FFMEDIA_PLAYER
import com.ts.tsavplayer.player.AVPlayer.Companion.VIDEO_RENDER_ANWINDOW
import java.io.File

class NativeWindowsActivity : AppCompatActivity(), SurfaceHolder.Callback {
    private  val TAG = "NativeWindowsActivity"
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
//        enableEdgeToEdge()
        requestWindowFeature(Window.FEATURE_NO_TITLE)
        setContentView(R.layout.activity_native_windows)
//        ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main)) { v, insets ->
//            val systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars())
//            v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom)
//            insets
//        }
        var file=File("/sdcard/midway.mp4")
        if (file.exists()){
            Log.e(TAG,"fileooooo")
        }

        findViewById<SurfaceView>(R.id.surface_native_windows).holder.addCallback(this)
    }
    var mAVPlayer=AVPlayer();
    var playHanlder=0L;
    override fun surfaceCreated(holder: SurfaceHolder) {

        playHanlder=mAVPlayer.init(
            "/sdcard/midway.mp4",
            FFMEDIA_PLAYER,VIDEO_RENDER_ANWINDOW,holder.surface)
    }

    override fun surfaceChanged(holder: SurfaceHolder, format: Int, width: Int, height: Int) {
        mAVPlayer?.play(playHanlder)
    }

    override fun surfaceDestroyed(holder: SurfaceHolder) {

    }
}